<template>
  <div ref="net_sec" class="net-sec" style="width: 100%;
  height: 50%;"></div>
</template>

<script>
import * as echarts from "echarts";
import { mapState } from "vuex";
export default {
  data() {
    return {
      chartInstance: {},
    };
  },
  computed: {
    ...mapState(["theme"]),
  },
  methods: {
    initChart() {
      // 初始化对象
      this.chartInstance = echarts.init(this.$refs.net_sec, this.theme);
      let option = {
        color: ["#21ffeb", "#36adff"],
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#6a7985",
            },
          },
        },
        legend: {
          icon: "circle",
          bottom: "3%",
          textStyle: {
            color: "rgba(255,255,255,0.8)",
          },
        },

        grid: {
          left: "3%",
          right: "0%",
          bottom: "15%",
          top: "8%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            boundaryGap: false,
            data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
            axisTick: {
              show: false,
            },
            axisLine: {
              show: false,
            },
       axisLabel: {
              show: true, color: "rgba(255,255,255,0.5)",
  
            },
          },
        ],
        yAxis: [
          {
            type: "value",
            splitLine: {
              lineStyle: {
                color: "#1a1f6d",
                width: 1,
              },
            },
               axisLabel: {
              show: true, color: "rgba(255,255,255,0.5)",
  
            },
          },
        ],

        series: [
          {
            symbol: "circle",
            name: "规格",
            type: "line",
            smooth: true,
            itemStyle: {
              color: "#21ffeb",
            },

            showSymbol: false,
            areaStyle: {
              opacity: 0.6,
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: "#21ffeb",
                },
                {
                  offset: 1,
                  color: "transparent",
                },
              ]),
            },
            emphasis: {
              focus: "series",
            },
            data: [140, 232, 101, 264, 90, 340, 250],
          },
          {
            symbol: "circle",
            name: "参数",
            type: "line",
            smooth: true,
            itemStyle: {
              color: "#36adff",
            },

            showSymbol: false,
            areaStyle: {
              opacity: 0.8,
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: "rgb(0, 221, 255)",
                },
                {
                  offset: 1,
                  color: "transparent",
                },
              ]),
            },
            emphasis: {
              focus: "series",
            },
            data: [120, 282, 111, 234, 220, 340, 310],
          },
        ],
      };
      this.chartInstance.setOption(option);
    },
  },
  mounted() {
    this.initChart();
        // 添加随页面变化而变化
    window.addEventListener('resize', () => {
       this.chartInstance.resize()
    })
  },
      destroyed () {
    window.removeEventListener("resize", () => {
      this.chartInstance.resize();
    });
  },
  watch: {
    theme(newValue, oldValue) {
      this.chartInstance.dispose();
      this.initChart();
    },
  },
};
</script>

<style lang="scss" scoped>
.net-sec {
  width: 100%;
  height: 50%;
}
</style>